package com.nami.ucenter.application.dubbo.convertor;

import cn.hutool.core.collection.CollUtil;
import com.nami.ucenter.client.response.UserDTO;
import com.nami.ucenter.domain.model.UserModel;


import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class UserModelToUserDTOAssembler {

    public static UserDTO toDTO(final UserModel userModel) {
        if (userModel == null) {
            return null;
        }
        UserDTO userDTO = new UserDTO();
        userDTO.setUserId(userModel.getUserId());
        userDTO.setMobile(userModel.getMobile());
        userDTO.setEmail(userModel.getEmail());
        userDTO.setNickname(userModel.getNickname());
        userDTO.setAvatarUrl(userModel.getAvatarUrl());
        userDTO.setAppKey(userModel.getAppKey());
        userDTO.setStatus(userModel.getStatus());
        userDTO.setGender(userModel.getGender());
        return userDTO;
    }

    public static List<UserDTO> toDTOs(List<UserModel> users) {
        if (CollUtil.isEmpty(users)) {
            return null;
        }
        List<UserDTO> userDTOs = new ArrayList<UserDTO>(users.size());
        for (UserModel userModel : users) {
            if (userModel == null) {
                continue;
            }
            userDTOs.add(toDTO(userModel));
        }
        return userDTOs;
    }

}
